/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AjouConquerorBeans;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author ajou
 */
@Stateless
public class LoginFacade extends AbstractFacade<Login> {

    @PersistenceContext(unitName = "AjouConquerorServer-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public LoginFacade() {
        super(Login.class);
    }

    public String AccountID(String Id, String pass) {
        String check = "success";
        Boolean flag = true;
        for (Login p : findAll()) {
            if (p.getUerId().equals(Id)) {
                check = "fail";
                flag = false;
            }
        }
        if (flag) {
            Login q = new Login();
            q.setUerId(Id);
            q.setPassword(pass);
            create(q);
        }
        return check;
    }

    public String CheckCorrectIDPASS(String Id, String pass) {
        String check = "fail";
        for (Login p : findAll()) {
            if (p.getUerId().equals(Id)) {
                if (p.getPassword().equals(pass)) {
                    check = "success";
                }
            }
        }
        return check;
    }
}
